package com.traffic.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.utils.BaseUtil;
import com.traffic.domain.FamilyMigrate;
import com.traffic.service.IFamilyMigrateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 亲人移居信息Controller
 * 
 * @author zzs
 * @date 2024-11-11
 */
@RestController
@RequestMapping("/migrate")
public class FamilyMigrateController extends BaseController
{
    @Autowired
    private IFamilyMigrateService familyMigrateService;

    /**
     * 查询亲人移居信息列表
     */
    @RequiresPermissions("information:migrate:list")
    @GetMapping("/list")
    public TableDataInfo list(FamilyMigrate familyMigrate)
    {
        Long curId= BaseUtil.getCurrentId();
        familyMigrate.setUserId(curId);
        startPage();
        List<FamilyMigrate> list = familyMigrateService.selectFamilyMigrateList(familyMigrate);
        return getDataTable(list);
    }

    /**
     * 导出亲人移居信息列表
     */
    @RequiresPermissions("information:migrate:export")
    @Log(title = "亲人移居信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FamilyMigrate familyMigrate)
    {
        List<FamilyMigrate> list = familyMigrateService.selectFamilyMigrateList(familyMigrate);
        ExcelUtil<FamilyMigrate> util = new ExcelUtil<FamilyMigrate>(FamilyMigrate.class);
        util.exportExcel(response, list, "亲人移居信息数据");
    }

    /**
     * 获取亲人移居信息详细信息
     */
    @RequiresPermissions("information:migrate:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(familyMigrateService.selectFamilyMigrateById(id));
    }

    /**
     * 新增亲人移居信息
     */
    @RequiresPermissions("information:migrate:add")
    @Log(title = "亲人移居信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FamilyMigrate familyMigrate)
    {
        Long curId= BaseUtil.getCurrentId();
        familyMigrate.setUserId(curId);
        return toAjax(familyMigrateService.insertFamilyMigrate(familyMigrate));
    }

    /**
     * 修改亲人移居信息
     */
    @RequiresPermissions("information:migrate:edit")
    @Log(title = "亲人移居信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FamilyMigrate familyMigrate)
    {
        return toAjax(familyMigrateService.updateFamilyMigrate(familyMigrate));
    }

    /**
     * 删除亲人移居信息
     */
    @RequiresPermissions("information:migrate:remove")
    @Log(title = "亲人移居信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(familyMigrateService.deleteFamilyMigrateByIds(ids));
    }
}
